<template>
  <div>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <div v-for="(item, index) in shoucarList" :key="index">
        <van-card :num="item.cou" :price="item.sell_price" :title="item.title" :thumb="item.thumb_path" v-if="item.cou <=0? false: true">
          <div slot="footer">
            <van-stepper v-model="item.cou" min="0" max="15" integer />
          </div>
        </van-card>
      </div>
    </van-pull-refresh>
    <div>
      <van-submit-bar :price="Getnumsum" button-text="提交订单" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'shiocar',
  data () {
    return {
      shoucarList: [],
      isLoading: false
    }
  },
  created () {
    this.getshoucarList()
  },
  methods: {
    async getshoucarList () {
      const { data: res } = await this.$http.get('/api/goods/getshopcarlist/87,88')
      this.shoucarList = res.message
    },
    onRefresh () {
      setTimeout(() => {
        this.$toast('刷新成功')
        this.isLoading = false
      }, 500)
    }
  },
  computed: {
    // 总价
    Getnumsum () {
      var num = 0
      this.shoucarList.forEach(item => {
        if (item.cou >= 0) {
          num += item.cou * item.sell_price
          return num
        }
      })
      return num * 100
    }
  }
}
</script>

<style lang="less" scoped>
.van-card {
  text-align: left;
}
</style>
